package com.water.controller.wx;

import com.water.entity.SyArea;
import com.water.entity.WxHuo;
import com.water.service.WxHuoService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

import static org.springframework.util.StringUtils.isEmpty;

/**
 * (WxHuo)表控制层
 *
 * @author makejava
 * @since 2020-12-21 15:11:30
 */
@Controller
@RequestMapping("wx")
public class WxHuoController {
    /**
     * 服务对象
     */
    @Resource
    private WxHuoService wxHuoService;

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @ResponseBody
    @GetMapping("selectOne")
    public WxHuo selectOne(Integer id) {
        return this.wxHuoService.queryById(id);
    }


    /**
     * 查询所有活动
     * @param model
     * @param wxHuo
     * @return
     */
    @RequestMapping(value = "huo",method = RequestMethod.GET)
    public String huo(Model model,WxHuo wxHuo){
      List<WxHuo> list=  wxHuoService.queryAll(wxHuo);
      model.addAttribute("wxhuo",list);
        return "sys/wx_huo";
    }

    /**
     * 跳到添加抄表
     * @param syArea
     * @param model
     * @return
     */
    @RequestMapping(value = "wx_huo_add",method = RequestMethod.GET)
    public String sys_area_add(SyArea syArea, Model model){
        return "sys/wx_huo_add";
    }

    /**
     * 添加抄表数据
     * @param
     * @param model
     * @return
     */
    @RequestMapping(value = "wx_huo_add1",method = RequestMethod.POST)
    public String sys_area_add1(WxHuo wxHuo, Model model){
        WxHuo syArea1=    this.wxHuoService.insert(wxHuo);
        if(!isEmpty(syArea1)){
            model.addAttribute("msg","添加成功");
            return "sys/wx_huo_add";
        }
        return "sys/wx_huo_add";
    }

    /**
     * 跳到修改
     * @param
     * @param model
     * @return
     */
    @RequestMapping(value = "wx_huo_update/{id}",method = RequestMethod.GET)
    public String sys_area_update(WxHuo wxHuo, Model model, @PathVariable("id") Integer id){
        WxHuo syArea1=this.wxHuoService.queryById(id);
        System.out.println(syArea1.toString()+"================================================");
        model.addAttribute("syArea1",syArea1);
        return "sys/wx_huo_update";
    }

    /**
     * 添加修改数据
     * @param
     * @param model
     * @return
     */
    @RequestMapping(value = "sys_huo_update1",method = RequestMethod.POST)
    public String sys_area_update1(WxHuo wxHuo, Model model){
        System.out.println(wxHuo.toString());
        try{
            WxHuo   syemp1=  this.wxHuoService.update(wxHuo);
            return "success";
        }catch (Exception e){
            e.printStackTrace();
        }
        model.addAttribute("msg","修改失败");
        return "sys/wx_huo_update";
    }

    /**
     * 删除数据
     * @param id
     * @param model
     * @return
     */
    @RequestMapping(value = "sys_del/{id}",method= RequestMethod.GET)
    public String sys_empdel(@PathVariable("id") Integer id,Model model){
        System.out.println(id);
        boolean bo=    this.wxHuoService.deleteById(id);
        if (bo==true){
            return "redirect:/wx/huo";
        }
        return "redirect:/wx/huo";
    }

    /**
     * 查询title
     * @param wxHuo
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "findTitle",method = RequestMethod.POST)
    public List<WxHuo> findTitle(WxHuo wxHuo){
        List<WxHuo> list=this.wxHuoService.queryAll(wxHuo);
        return list;
    }

}